#include "button.h"
#include <lv_font_source_han_sans_bold.h>  // 确保包含正确的字体头文件

// 图像按钮
lv_obj_t * create_imgbtn(lv_obj_t * parent, int x, int y, int w, int h, char * pic_path)
{
    static lv_style_t style_pr;
    lv_style_init(&style_pr);
    lv_style_set_img_recolor_opa(&style_pr, LV_OPA_30);
    lv_style_set_img_recolor(&style_pr, lv_color_black());
    lv_style_set_transform_height(&style_pr, 20);

    lv_obj_t * imgbtn = lv_imgbtn_create(parent);
    if (imgbtn == NULL) {
        LV_LOG_ERROR("lv_imgbtn_create fail:");
        return NULL;
    }

    lv_obj_set_size(imgbtn, w, h);
    lv_imgbtn_set_src(imgbtn, LV_IMGBTN_STATE_RELEASED, NULL, pic_path, NULL);
    lv_obj_add_style(imgbtn, &style_pr, LV_STATE_PRESSED);

    // 设置按钮位置和对齐方式
    lv_obj_set_pos(imgbtn, x, y);

    return imgbtn;
}

// 普通按钮
lv_obj_t * create_btn(lv_obj_t * parent, int x, int y, int w, int h, const char * text)
{
    lv_obj_t * btn = lv_btn_create(parent);
    lv_obj_set_size(btn, w, h);
    lv_obj_set_pos(btn, x, y);

    lv_obj_t * label = lv_label_create(btn);
    lv_obj_set_style_text_font(label, &lv_font_source_han_sans_bold_20, 0);
    lv_label_set_text(label, text);
    lv_obj_center(label);

    return btn;
}